package com.yq.front.util;

import com.yq.api.dto.UserTO;
import com.yq.front.vo.UserVO;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yq on 16-5-26.
 */
public class UserVOUtil {

    public static UserVO toUserVO(UserTO userTO){
        if(userTO == null){
            return null;
        }
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(userTO, userVO);
        return userVO;
    }

    public static List<UserVO> toUserVOList(List<UserTO> userTOList){
        if(userTOList == null){
            return null;
        }
        List<UserVO> userVOList = new ArrayList<UserVO>();
        if(userTOList.isEmpty()){
            return userVOList;
        }
        for (UserTO userTO : userTOList) {
            UserVO userVO = new UserVO();
            BeanUtils.copyProperties(userTO,userVO);
            userVOList.add(userVO);
        }
        return userVOList;
    }

    public static UserTO toUserTO(UserVO userVO){
        if(userVO == null){
            return null;
        }
        UserTO userTO = new UserTO();
        BeanUtils.copyProperties(userVO, userTO);
        return userTO;
    }

    public static List<UserTO> toUserTOList(List<UserVO> userVOList){
        if(userVOList == null){
            return null;
        }
        List<UserTO> userTOList = new ArrayList<UserTO>();
        if(userVOList.isEmpty()){
            return userTOList;
        }

        for (UserVO userVO : userVOList) {
            UserTO userTO = new UserTO();
            BeanUtils.copyProperties(userVO, userTO);
            userTOList.add(userTO);
        }

        return userTOList;
    }

    /**
     * 回写用户信息
     * */
    public static void writeBack(UserTO userTO, UserVO userVO) {
        if(userVO == null || userTO == null){
            return;
        }
        BeanUtils.copyProperties(userTO, userVO);
    }
}
